package project.menu.ordermenu.listmadedorders;

import java.util.ArrayList;

import project.controllers.Controller;
import project.controllers.Messager;
import project.controllers.Printer;
import project.menu.IMenu;
import project.menu.IMenuItem;
import project.work.Navigator;
import api.controller.IAutoservice;
import api.entitites.IOrder;

public class MadedOrdersByBeginingDate implements IMenuItem {

	private String name = " Sort by begining date";
	private final Integer id = 2;
	private static IMenu submenu;
	private Controller controller;
	private Navigator navigator;

	public MadedOrdersByBeginingDate() {
		controller = Controller.getInstance();
		navigator = Navigator.getInstance();
	}

	public Integer getId() {
		return id;
	}

	public String getNameItem() {
		return name;
	}

	public static void setMenu(IMenu menu) {
		submenu = menu;
	}

	public void action(IAutoservice autoservice) {
		// sort by begining date
		ArrayList<IOrder> temp=autoservice.SortMadeOrderByPeriodByBeginningDate(
				controller.getBeginDate(), controller.getEndDate());
		for (IOrder order :temp ) {		
			Printer.printMessage(Messager.ORDER_NUMBER+ order.getNumberOrder());
		}
		
		navigator.drawMenu(submenu);

	}

}
